package san.entity.article;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.dao.BaseEntity;

@Entity
@Table(name = "article")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Article extends BaseEntity {
	/**
	 * 文章类型
	 */
	private static final long serialVersionUID = 2538430116508119997L;
	private String articletype;
	@OneToMany(mappedBy = "article", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@OrderBy(value = "insertDate")
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	private List<ArticleItem> articleItems = new ArrayList<ArticleItem>();

	public List<ArticleItem> getArticleItems() {
		return articleItems;
	}

	public void setArticleItems(List<ArticleItem> articleItems) {
		this.articleItems = articleItems;
	}

	public String getArticletype() {
		return articletype;
	}

	public void setArticletype(String articletype) {
		this.articletype = articletype;
	}

	/*
	 * 添加文章
	 */
	public void addArticleItem(ArticleItem articleitem) {
		if (!this.articleItems.contains(articleitem)) {
			this.articleItems.add(articleitem);
			articleitem.setArticle(this);
		}
	}
}
